/**
 * Created on Apr 22, 2007
 */
package bsh.commands;

import x.java.lang.System;
import bsh.CallStack;
import bsh.Interpreter;
/**
 * @author qiangli
 * 
 */
public class runcmd {

	public static String usage() {
		return "usage: runcmd(String cmd, String arg)";
	}

	public static void invoke(Interpreter env, CallStack callstack, String cmd) {
		try {
			
			exec(cmd, new String[0]);
		} catch (Exception e) {
			System.out().println(e);
		}
	}

	public static void invoke(Interpreter env, CallStack callstack, String cmd,
			String file) {
		try {
			String[] args = null;
			if (file == null) {
				args = new String[0];
			} else {
				if (file.startsWith("v:/") || file.startsWith("/")) {
					args = new String[] {file};
				} else {
					String dir = x.java.lang.System.getProperty("user.dir");
					dir = dir+(dir.endsWith("/")?"":"/")+file;
					args = new String[] {dir};
				}
			}
			exec(cmd, args);
		} catch (Exception e) {
			System.out().println(e);
		}
	}

	private static void exec(String cmd, String[] args) {
		System.out().println("TODO: exec "+cmd);
	}
}